<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>解构赋值</title>
</head>
<body>
<script>
    let a, b, c;
    let arr = [10, 20];
    {//数组的解构赋值
        // [a, b] = arr;
        [b, a] = arr;
        console.log(a);
        console.log(b);
    }
    {//对象的解构赋值
        let obj2 = {code: 100, msg: 200, data: 300};
        let {data} = obj2;

        let obj = {
            a: 100,
            b: 200
        };
        // ({a,b} = obj)
        ({b, a} = obj)
        console.log(a);
        console.log(b);
    }

    //...  扩展(展开)运算符
    {
        let arr = [1, 2, 3, 4];
        console.log(arr);
        console.log(...arr);
    }

    {
        let arr = [1, 2, 3, 4, 5];
        let a, b, more;
        [a, b, ...more] = arr;
        console.log(a);
        console.log(b);
        console.log(more);
    }
    {
        function fn() {
            //arguments 方法的参数集合
            console.log(arguments)
            console.log(...arguments)
        }

        fn(1, 2, 3, 4, 5)
    }
    {
        let obj = {a: 1, b: 1, c: 1};
        // console.log(...obj);
    }
    {    // 别名
        let obj = {
            name: "haha",
            age: 18,
            obj2: {
                name: "hehe",
                age: 16,
            }
        }
        let {name, age, obj2: {name: obj2name}} = obj;
        console.log(name, obj2name);
        console.log(obj2name);
    }


</script>
</body>
</html>